<?php

namespace addons\qingdongams\model;

use think\Model;
use traits\model\SoftDelete;

/**
 *评论表
 */
class Discuss extends Model
{
    use SoftDelete;

    // 表名,不含前缀
    const   CUSTOMER_TYPE = 'customer';
    const   EVENT_TYPE = 'event';//客户
    const   WORKORDER_TYPE = 'workorder';//日程
    const   CONTRACT_TYPE = 'contract';// 工单评论
    const   EXAMINE_TYPE = 'examine';//订单
    const   CONSUME_TYPE = 'consume';//审批
    const   QUOTE_TYPE = 'quote';//费用
    const   ORDER_TYPE = 'order';//报价单
    protected $name = 'qingdongams_discuss';//订单
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public function staff()
    {
        return $this->belongsTo(Staff::class, 'create_staff_id', 'id')->field('id,name,img,post');
    }

    public function getShowStaffIdAttr($value)
    {
        return Staff::where(['id' => ['in', explode(',', $value)]])->field('id,name,img,post')->select();
    }

    //
    public function getFileIdsAttr($value)
    {
        $files = explode(',', $value);
        $result = [];
        foreach ($files as $fid) {
            if ($fid) {
                $result[] = ['url' => cdnurl(File::getUrl($fid), true), 'id' => $fid];
            }
        }

        return $result;
    }

    public function getCreatetimeAttr($value)
    {
        return date('Y-m-d H:i', $value);
    }
}
